package com.exam.sacrifice.ui.mine;

import android.os.Handler;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.exam.commonbiz.base.BaseActivity;
import com.exam.commonbiz.base.BaseViewModel;
import com.exam.commonbiz.util.OnFastClickListener;
import com.exam.sacrifice.R;
import com.exam.sacrifice.databinding.ActivityAddressListBinding;
import com.exam.sacrifice.ui.adapter.AddressListAdapter;
import com.exam.sacrifice.ui.bean.RechargeInfo;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

public class AddressListActivity extends BaseActivity<BaseViewModel, ActivityAddressListBinding> {

    @Override
    protected int getLayoutId() {
        return R.layout.activity_address_list;
    }

    @Override
    public void initData() {

        binding.include.tvTitle.setText("收货地址");
        binding.include.ivback.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                finish();
            }
        });

        binding.smartRefreshLayout.setEnableLoadMore(false);
        binding.smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        binding.smartRefreshLayout.finishRefresh();
                    }
                }, 1500);
            }
        });

        List<RechargeInfo> rechargeInfoList = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            rechargeInfoList.add(new RechargeInfo());
        }

        AddressListAdapter rechargeCenterAdapter = new AddressListAdapter();
        LinearLayoutManager gridLayoutManager = new LinearLayoutManager(context);
        binding.recyclerView.setLayoutManager(gridLayoutManager);
        binding.recyclerView.setAdapter(rechargeCenterAdapter);
        rechargeCenterAdapter.setNewData(rechargeInfoList);
        rechargeCenterAdapter.setOnItemClickListener(new AddressListAdapter.OnItemClickListener() {

            @Override
            public void onItemClick(RechargeInfo item) {

            }
        });
    }
}